﻿using System.Data.Entity;

namespace OpenRiaServices.Issue92.Web.Models
{
    public partial class Issue92Context : DbContext
    {
        public Issue92Context()
            : this("Issue92Context")
        {
        }

        /// <summary>
        /// Creates database context for Issue92 Benchmark. This constructor should be used for tests only.
        /// </summary>
        /// <param name="nameOrConnectionString">Either the database name or a connection string.</param>
        public Issue92Context(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {
            this.Configuration.LazyLoadingEnabled = false;
        }

        public virtual DbSet<ParentEntity> ParentEntities { get; set; }

        public virtual DbSet<ChildEntity> ChildEntities { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<ParentEntity>()
                .HasMany(e => e.ChildEntities)
                .WithRequired(e => e.ParentEntity)
                .HasForeignKey(e => e.ParentEntityId)
                .WillCascadeOnDelete(true);
        }
    }
}
